package ch.ethz.eai.data;

import ch.ethz.eai.data.WeatherStatus;


// This is the main object that our web service will
// return to its clients. It contains an integer return 
// code that identifies the execution status (+1 for 
// success and -1 for failure) and an optional string 
// message (that usually contains the main part of the 
// response)

public class ResponseMessage 
{
	public static int SUCCESS = +1;
	public static int FAILURE = -1;
	public static int ADDITIONAL_ACTION_NEEDED = -2;
	
	private int    status_code;
	private String status_msg;
	
	private String   weatherstatus;
	private String[] addresses;
	private String[] venues;
	
	public ResponseMessage()
	{
		super();
	}
	
	// We use this constructor when we want to create a simple response
	// message that contains a status code and a status description
	public ResponseMessage(int rcode, String rmsg)
	{
		super();
		this.status_code = rcode;
		this.status_msg = rmsg;
		this.addresses = new String[0];
		this.weatherstatus = WeatherStatus.STAT_UNDEFINED + "";
		this.venues = new String[0];
	}
	
	// We use this constructor when we want to create a response message that 
	// contains a list of possible addresses that the user can choose from
	public ResponseMessage(int rcode, String rmsg, String[] raddresses)
	{
		super();
		this.status_code = rcode;
		this.status_msg = rmsg;
		this.addresses = raddresses;
		this.weatherstatus = WeatherStatus.STAT_UNDEFINED + "";
		this.venues = new String[0];
	}
	
	// We use this constructor when we want to create a response message that
	// contains the weather status along with a list of proposed venues
	public ResponseMessage(int rcode, String rmsg, int ws, String[] rvenues)
	{
		super();
		this.status_code = rcode;
		this.status_msg = rmsg;
		this.addresses = new String[0];
		this.weatherstatus = ws + "";
		this.venues = rvenues;
	}
	
	public void setCode(int rcode)
	{
		this.status_code = rcode;
	}
	
	public int getCode()
	{
		return this.status_code;
	}
	
	public void setMessage(String rmsg)
	{
		this.status_msg = rmsg;
	}
	
	public String getMessage()
	{
		return this.status_msg;
	}
	
	public void setAddresses(String[] raddresses)
	{
		this.addresses = raddresses;
	}
	
	public String[] getAddresses()
	{
		return this.addresses;
	}
	
	public void setVenues(String[] rvenues)
	{
		this.venues = rvenues;
	}
	
	public String[] getVenues()
	{
		return this.venues;
	}
	
	public void setWeatherStatus(int ws)
	{
		this.weatherstatus = ws + "";
	}
	
	public void setWeatherStatus(String ws)
	{
		this.weatherstatus = ws;
	}
	
	public String getWeatherStatus()
	{
		return this.weatherstatus;
	}
	
	public String printMainInfo()
	{
		return "RESPONSE_CODE: " + this.status_code + ", RESPONSE_MSG: " + this.status_msg;
	}
	
	public String printAdditionalInfo()
	{
		String resp = "";
		
		resp += "ADDRESS_LIST: ";
		
		if (this.addresses.length == 0)
		{
			resp += "Empty \n";
		}
		else
		{
			for(int i=0; i < this.addresses.length; i++)
			{
				resp += addresses[i] + "\n";
			}
		}
		
		resp += "WEATHER_STATUS: ";
		
		if (this.weatherstatus.equalsIgnoreCase(WeatherStatus.STAT_UNDEFINED + ""))
		{
			resp += "Undefined \n";
		}
		else
		{
			resp += this.weatherstatus +"\n";
		}
		
		resp += "VENUE_LIST: ";
		if (this.venues.length == 0)
		{
			resp += "Empty \n";
		}
		else
		{
			for(int i=0; i < this.venues.length; i++)
			{
				resp += venues[i] + "\n";
			}
		}
		
		return resp;
	}
	
	public String toString()
	{
		return printMainInfo() + "\n" + printAdditionalInfo();
	}

}
